'use strict';

const { get_addNew_cmd, delete_func, delete_node } = require('../Middleware/mid_interface');

const Controller = require('egg').Controller;

class SettingController extends Controller {
    async get_setting_config() {
        const { ctx } = this;
        var data = await get_addNew_cmd();
        ctx.body = data;
    }
    async set_password() {
        const { ctx } = this;
        ctx.body = 'set_password';
    }
    async del_node() {
        const { ctx } = this;
        const { name } = ctx.request.body;
        var msg = await delete_node(name);
        if (msg) {
            ctx.body = msg;
        } else {
            ctx.body = `节点${name}不存在`;
        }
    }
    async del_func() {
        const { ctx } = this;
        const { name } = ctx.request.body;
        var msg = await delete_func(name);
        ctx.body = msg;
    }
}

module.exports = SettingController;
/**
 * /get_setting_config 
 * POST方法，用于获取设置项
 * ·入参 
 *      token
 * ·回参 
 *      data {
 *           addNewEdge: "",  //一件部署边缘侧的命令
 *           openfaas: "admin", //返回用户名
 *           nodes:[{name:"CentosMaster",node_id:13},],//节点集合
 *           function:[{name:"nodeinfo",function_id:13},]
 *       }
 *      code 1-成功 0-失败
 *      msg 返回的提示消息："获取设置项内容成功！"
 * 
 * /set_password 
 * POST方法，用于设置密码
 * ·入参 
 *      token
 *      username 用户名
 *      password 密码的MD5
 * ·回参 
 *      code 1-成功 0-失败
 *      msg 返回的提示消息："修改密码成功！"
 * 
 * /del_node 
 * POST方法，用于删除节点
 * ·入参 
 *      token
 *      node_id 节点ID
 * ·回参 
 *      code 1-成功 0-失败
 *      msg 返回的提示消息："删除节点成功！"
 * 
 * /del_func 
 * POST方法，用于删除函数
 * ·入参 
 *      token
 *      func_id 函数ID
 * ·回参 
 *      code 1-成功 0-失败
 *      msg 返回的提示消息："删除函数成功！"
 */